package com.hzm.test.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;


@Configuration
//@ConditionalOnBean(RedisCacheManager.class)
public class CacheConfig extends CachingConfigurerSupport {

    @Autowired
    private LoggingCacheErrorHandler errorHandler;

    @Autowired
    private RedisCacheManager redisCacheManager;

    /**
     * 重写这个方法，目的是用以提供默认的cacheManager
     */
    @Override
    public CacheManager cacheManager() {
        return redisCacheManager;
    }

    /**
     * 如果cache出错， 我们会记录在日志里，方便排查，比如反序列化异常
     */
    @Override
    public CacheErrorHandler errorHandler() {
        return errorHandler;
    }

}
